package code.db.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.RowMapper;

import code.domain.Column;

public class ColumnRowMapper implements RowMapper<Column> {

	public Column mapRow(ResultSet rs, int paramInt)
			throws SQLException {
		Column column = new Column();
		String name = rs.getString("COLUMN_NAME");
		String desc = rs.getString("COMMENTS");
		if(StringUtils.isBlank(desc)){
			desc = "";
		}
		String dataType = rs.getString("DATA_TYPE");
		String nullable = rs.getString("NULLABLE");
		String defaultValue = rs.getString("DATA_DEFAULT");
		if(StringUtils.isBlank(defaultValue)){
			defaultValue = "";
		}
		column.setName(name);
		column.setDesc(desc);
		column.setType(dataType);
		column.setNullable(StringUtils.equals(nullable, "Y")? "1": "0");
		column.setDefaultValue(defaultValue);
		return column;
	}

}
